/**
 * 
 */
package com.platform.common.utils.util.dynamic.impl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

import com.platform.common.utils.util.dynamic.DynamicProxyInvocationHandler;
import com.platform.common.utils.util.dynamic.IDynamicInterceptor;
import com.platform.common.utils.util.dynamic.IDynamicProxyFactory;

/**
 * <pre>
 * 功能：动态代理工厂实现
 * </pre>
 * 
 * @author wei.gao
 */
public class DynamicProxyFactoryImpl implements IDynamicProxyFactory {
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.platform.core.util.dynamic.IDynamicProxyFactory#createProxy(java.
	 * lang.Class, java.lang.Object,
	 * com.platform.core.util.dynamic.IDynamicInterceptor)
	 */
	@SuppressWarnings("unchecked")
	public <T> T createProxy(Class<T> clazz, T target, IDynamicInterceptor interceptor) {
		InvocationHandler handler = new DynamicProxyInvocationHandler(target, interceptor);
		return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { clazz }, handler);
	}
}
